from paddlenlp import Taskflow
import paddle
import jieba
import jieba.analyse
tar_str = "飞桨以百度多年的深度学习技术研究和业务应用为基础，集核心框架、基础模型库、端到端开发套件、丰富的工具组件、星河社区于一体，是中国首个自主研发、功能丰富、开源开放的产业级深度学习平台"

'''
print('jieba')
#分词
print(list(jieba.cut(tar_str)))

#关键词提取
print(list(jieba.analyse.extract_tags(tar_str, topK=3)))
print(list(jieba.analyse.textrank(tar_str, topK=3)))

print('===============')
print('paddlenlp')

#中文分词
seg = Taskflow('word_segmentation')
print(seg(tar_str))

seg_fast = Taskflow("word_segmentation", mode="fast")
print(seg_fast(tar_str))

seg_accurate = Taskflow("word_segmentation", mode="accurate")
print(seg_accurate(tar_str))

'''
print('ner==============')

#命名实体识别
ner = Taskflow("ner")
print(ner(tar_str))

ner = Taskflow("ner", entity_only=True) 
print(ner(tar_str))

ner = Taskflow("ner", mode="fast")
print(ner(tar_str))

print('pos==============')


#词性标注
tag = Taskflow("pos_tagging")
print(tag(tar_str))


tar_str = "作为老的四星酒店，房间依然很整洁，相当不错。机场接机服务很好，可以在车上办理入住手续，节省时间。"

print("senta==============")

#情感分析
senta = Taskflow("sentiment_analysis")
print(senta(tar_str))

senta = Taskflow("sentiment_analysis", model="skep_ernie_1.0_large_ch")
print(senta(tar_str))

schema = ['情感倾向[正向，负向]']
senta = Taskflow("sentiment_analysis", model="uie-senta-base", schema=schema)
print(senta(tar_str))

schema =  [{"评价维度":["房间", "情感倾向[正向,负向,未提及]"]}]
senta = Taskflow("sentiment_analysis", model="uie-senta-base", schema=schema)
print(senta(tar_str))
